package com.kern.socketdemo.demo1;

import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.ServerSocket;
import java.net.Socket;

/**
 *  TCP 通信 服务器端
 * Created by caoshi at 7:28 2021-07-22
 */
public class TCPServer {

    public static void main(String[] args) throws IOException {
        // 服务端 socket, 指定启动 port
        ServerSocket serverSocket = new ServerSocket(8989);
        Socket accept = serverSocket.accept();
        InputStream input = accept.getInputStream();

        DataInputStream dis = new DataInputStream(input);
        String str = dis.readUTF();
        System.out.println(str);

        dis.close();
        input.close();
        accept.close();
        serverSocket.close();
    }


}
